//
//  MBProgressHUD+Add.m
//  视频客户端
//
//  Created by mj on 13-4-18.
//  Copyright (c) 2013年 itcast. All rights reserved.
//

#import "MBProgressHUD+Add.h"

@implementation MBProgressHUD (Add)

#pragma mark 显示信息
+ (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view
{
    [MBProgressHUD showMessag:text toView:view afterDelay:0];
}

#pragma mark 显示错误信息
+ (void)showError:(NSString *)error toView:(UIView *)view{
    [self hideHUDForView:view animated:NO];
    [self show:error icon:@"error.png" view:view];
}

+ (void)showSuccess:(NSString *)success toView:(UIView *)view
{
    [self hideHUDForView:view animated:NO];
    [self show:success icon:@"success.png" view:view];
}

#pragma mark 显示错误信息
+ (void)showError:(NSString *)error toView:(UIView *)view delayForHidden:(NSTimeInterval)afterDelay{
    [MBProgressHUD showMessag:error toView:view afterDelay:afterDelay];
}

+ (void)showError:(NSString *)error toView:(UIView *)view noHidden:(BOOL)noHidden{
    MBProgressHUD *hud = [MBProgressHUD showMessag:error toView:view isDelayHiden:NO];
    hud.mode = MBProgressHUDModeText;
}

+ (void)showSuccess:(NSString *)success toView:(UIView *)view delayForHidden:(NSTimeInterval)afterDelay
{
    [self hideHUDForView:view animated:NO];
    [MBProgressHUD showMessag:success toView:view afterDelay:afterDelay];
}

#pragma mark 显示一些信息
+ (MBProgressHUD *)showMessag:(NSString *)message toView:(UIView *)view isDelayHiden:(BOOL)hiden {
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.label.text = message;
//    hud.bezelView.color = RGBA(105, 105, 105, 0.75);
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // YES代表需要蒙版效果
    hud.dimBackground = NO;
    if (hiden) {
        [hud hide:YES afterDelay:30.0];
    }
    return hud;
}

+ (MBProgressHUD *)showMessag:(NSString *)message toView:(UIView *)view afterDelay:(NSTimeInterval)afterDelay{
    if(afterDelay==0){
        afterDelay = message.length>15?2.5:1.5;
    }
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
//    hud.color = RGBA(105, 105, 105, 0.75);
    hud.detailsLabelText = message;
    hud.detailsLabelFont = [UIFont boldSystemFontOfSize:16.0f];
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // YES代表需要蒙版效果
    hud.dimBackground = NO;
    hud.mode = MBProgressHUDModeText;
    [hud hide:YES afterDelay:afterDelay];
    return hud;
}
//lnn
+ (MBProgressHUD *)showMessage:(NSString *)message
{
    return [self showMessage:message toView:nil];
}
#pragma mark lnn 显示一些信息
+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.labelText = message;
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    // YES代表需要蒙版效果
    hud.dimBackground = YES;
    return hud;
}
/** lnn 消失 */
+ (void)hideHUD
{
    [self hideHUDForView:nil];
}
+ (void)hideHUDForView:(UIView *)view
{
    [self hideHUDForView:view animated:YES];
}
@end
